home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 51.4 KB | 1,699 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UDocument.cp
- // Copyright © 1984-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #ifndef __UDOCUMENT__
- #include "UDocument.h"
- #endif
-
- // MacApp
-
- // #ifndef __UAPPLICATION__
- // #include "UApplication.h"
- // #endif
-
- #ifndef __UBEHAVIOR__
- #include "UBehavior.h"
- #endif
-
- #ifndef __UCLIPBOARDMGR__
- #include "UClipboardMgr.h"
- #endif
-
- #ifndef __UCOREERRORMGR__
- #include "UCoreErrorMgr.h"
- #endif
-
- #ifndef __UCOREGLOBALS__
- #include "UCoreGlobals.h"
- #endif
-
- #ifndef __UCOREUTILITIES__
- #include "UCoreUtilities.h"
- #endif
-
- #ifndef __UDESIGNATOR__
- #include "UDesignator.h"
- #endif
-
- #ifndef __UDISPATCHER__
- #include "UDispatcher.h"
- #endif
-
- #ifndef __UERRORMGR__
- #include "UErrorMgr.h"
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include "UMacAppGlobals.h"
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- #ifndef __UMEMORY__
- #include "UMemory.h"
- #endif
-
- #ifndef __UMENUMGR__
- #include "UMenuMgr.h"
- #endif
-
- #ifndef __UPRINTHANDLER__
- #include "UPrintHandler.h"
- #endif
-
- #ifndef __USCRIPTABLEOBJECT__
- #include "UScriptableObject.h"
- #endif
-
- #ifndef __USCRIPTING__
- #include "UScripting.h"
- #endif
-
- #ifndef __UVIEWSERVER__
- #include "UViewServer.h"
- #endif
-
- #ifndef __UWINDOW__
- #include "UWindow.h"
- #endif
-
- // Toolbox
-
- #ifndef __AEREGISTRY__
- #include <AERegistry.h>
- #endif
-
- //========================================================================================
- // static data members
- //========================================================================================
- short TDocument::gNumUntitled = 1; // call the first document "Untitled-1"
-
-
- //========================================================================================
- // CLASS CWindowIterator
- //========================================================================================
- #undef Inherited
- #define Inherited CObjectIterator
-
- //----------------------------------------------------------------------------------------
- // CWindowIterator::CWindowIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- CWindowIterator::CWindowIterator(const TDocument* itsDocument,
- ArrayIndex itsLowBound,
- ArrayIndex itsHighBound,
- Boolean itsForward) :
- CObjectIterator(itsDocument ? itsDocument->fWindowList : NULL, itsLowBound, itsHighBound, itsForward)
- {
- } // CWindowIterator::CWindowIterator
-
- //----------------------------------------------------------------------------------------
- // CWindowIterator::CWindowIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- CWindowIterator::CWindowIterator(const TDocument* itsDocument,
- Boolean itsForward) :
- CObjectIterator(itsDocument ? itsDocument->fWindowList : NULL, itsForward)
- {
- } // CWindowIterator::CWindowIterator
-
- //----------------------------------------------------------------------------------------
- // CWindowIterator::CWindowIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- CWindowIterator::CWindowIterator(const TDocument* itsDocument) :
- CObjectIterator(itsDocument ? itsDocument->fWindowList : NULL, kIterateForward)
- {
- } // CWindowIterator::CWindowIterator
-
- //----------------------------------------------------------------------------------------
- // CWindowIterator::~CWindowIterator:
- //----------------------------------------------------------------------------------------
- #pragma segment IteratorRes
-
- CWindowIterator::~CWindowIterator()
- {
- } // CWindowIterator::~CWindowIterator
-
- //========================================================================================
- // CLASS TRevertDocCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TCommand
-
- #pragma segment MASelCommand
- MA_DEFINE_CLASS_M1(TRevertDocCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TRevertDocCommand constructor
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- TRevertDocCommand::TRevertDocCommand()
- : fChangedDocument(NULL),
- fInProcessP(NULL)
- {
- } // TRevertDocCommand::TRevertDocCommand
-
- //----------------------------------------------------------------------------------------
- // TRevertDocCommand destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TRevertDocCommand::~TRevertDocCommand()
- {
- if (fInProcessP != NULL)
- *fInProcessP = FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // TRevertDocCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment MAReadFile
-
- void TRevertDocCommand::DoIt()
- {
- fChangedDocument->RevertDocument();
- fChangedDocument->ShowReverted();
- if (fInProcessP != NULL)
- *fInProcessP = FALSE;
- } // TRevertDocCommand::DoIt
-
- //----------------------------------------------------------------------------------------
- // TRevertDocCommand::IRevertDocCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- Boolean TRevertDocCommand::IRevertDocCommand(CommandNumber itsCommandNumber,
- TDocument* itsDocument)
- {
- this->ICommand(itsCommandNumber, itsDocument, kCantUndo, kDoesNotCauseChange, itsDocument);
- fChangedDocument = itsDocument;
-
- // Ask them if they are sure they want to revert.
- FailOSErr(MAInteractWithUser());
- CStr255 name;
- fChangedDocument->GetTitle(name);
-
- ParamText(name, gEmptyString, gEmptyString, gEmptyString);
- return (MacAppAlert(phRevert, NULL) == kYesButton);
- } // TRevertDocCommand::IRevertDocCommand
-
-
- //----------------------------------------------------------------------------------------
- // TRevertDocCommand::IRevertDocCommand
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TRevertDocCommand::IRevertDocCommand(TDocument* itsDocument,
- TAppleEvent* /* message */,
- TAppleEvent* /* reply */,
- Boolean* statusP)
- {
- this->ICommand(cRevert, itsDocument, kCantUndo, kDoesNotCauseChange, itsDocument);
- fChangedDocument = itsDocument;
- fInProcessP = statusP;
- if (fInProcessP != NULL)
- *fInProcessP = TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // TRevertDocCommand::MakeAppleEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- TAppleEvent* TRevertDocCommand::MakeAppleEvent()
- {
- MAVolatileInit(TAppleEvent*, mayFailEvent, NULL);
-
- FailInfo fi;
- Try(fi)
- {
- TAppleEvent* theEvent = new TAppleEvent;
- theEvent->IAppleEvent(kAEMiscStandards, kAERevert, gServerAddress, kAEWaitReply);
- mayFailEvent = theEvent;
-
- // Add the document as the direct object
- {
- CTempDesc docDesc;
- fChangedDocument->MakeObjectSpecifier(docDesc, formName);
- theEvent->WriteParameter(keyDirectObject, docDesc);
- }
-
- fi.Success();
- }
- else // Recover
- {
- mayFailEvent = (TAppleEvent *)FreeIfObject(mayFailEvent);
- fi.ReSignal();
- }
- return mayFailEvent;
- }
-
- //========================================================================================
- // CLASS TSaveDocCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TCommand
-
- #pragma segment MASelCommand
- MA_DEFINE_CLASS_M1(TSaveDocCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TSaveDocCommand constructor
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- TSaveDocCommand::TSaveDocCommand()
- : fDocument(NULL),
- fSavingState(kAskSave),
- fMessage(NULL),
- fReply(NULL)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TSaveDocCommand destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TSaveDocCommand::~TSaveDocCommand()
- {
- // NOTE: We deliberately do not dispose of fMessage and fReply.
- }
-
- //----------------------------------------------------------------------------------------
- // TSaveDocCommand::ISaveDocCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TSaveDocCommand::ISaveDocCommand(CommandNumber itsCommandNumber,
- TDocument* itsDocument)
- {
- this->ICommand(itsCommandNumber, itsDocument, kCantUndo,
- kDoesNotCauseChange, NULL);
- fDocument = itsDocument;
- fSavingState = kDoSave;
- }
-
- //----------------------------------------------------------------------------------------
- // TSaveDocCommand::ISaveDocCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TSaveDocCommand::ISaveDocCommand(TDocument* itsDocument,
- TAppleEvent* message,
- TAppleEvent* reply)
- {
- // This doesn't actually prepare to save anything since we don't have any idea
- // what kind of document you have.
- CommandNumber itsCommandNumber = cSave;
-
- this->ICommand(itsCommandNumber, itsDocument, kCantUndo,
- kDoesNotCauseChange, NULL);
-
- fMessage = message;
- fReply = reply;
- fDocument = itsDocument;
- fSavingState = kDoSave; // Default so no data is inadvertantly lost.
- }
-
- //----------------------------------------------------------------------------------------
- // TSaveDocCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- void TSaveDocCommand::DoIt()
- {
- if (fDocument && fSavingState != kDontSave && fDocument->fCommitOnSave)
- fDocument->CommitLastCommand();
- }
-
- //----------------------------------------------------------------------------------------
- // TSaveDocCommand::MakeAppleEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- TAppleEvent* TSaveDocCommand::MakeAppleEvent()
- {
- MAVolatileInit(TAppleEvent*, mayFailEvent, NULL);
- FailInfo fi;
- Try(fi)
- {
- TAppleEvent* theEvent = new TAppleEvent;
- theEvent->IAppleEvent(kAECoreSuite, kAESave, gServerAddress, kAEWaitReply);
- mayFailEvent = theEvent;
- {
- CTempDesc theDocDesc;
- fDocument->MakeObjectSpecifier(theDocDesc, fDocument->GetSpecifierForm());
- theEvent->WriteParameter(keyDirectObject, theDocDesc);
- }
- fi.Success();
- }
- else // Recover
- {
- mayFailEvent = (TAppleEvent *)FreeIfObject(mayFailEvent);
- fi.ReSignal();
- }
- return mayFailEvent;
- }
-
- //========================================================================================
- // CLASS TCloseDocCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TCommand
-
- #pragma segment MASelCommand
- MA_DEFINE_CLASS_M1(TCloseDocCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TCloseDocCommand constructor
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- TCloseDocCommand::TCloseDocCommand()
- : fDocument(NULL),
- fSavingState(kUnknown),
- fMessage(NULL),
- fReply(NULL)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TCloseDocCommand destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TCloseDocCommand::~TCloseDocCommand()
- {
- // NOTE: We deliberately do not dispose of fMessage and fReply.
- }
-
- //----------------------------------------------------------------------------------------
- // TCloseDocCommand::ICloseDocCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TCloseDocCommand::ICloseDocCommand(CommandNumber itsCommandNumber,
- TDocument* itsDocument)
- {
- this->ICommand(itsCommandNumber, itsDocument, kCantUndo,
- kDoesNotCauseChange, NULL);
-
- fDocument = itsDocument;
-
- // // If this command is to notify another command then do a link.
- // if (linkedCommand)
- // this->LinkToSecondary(linkedCommand);
-
- if (fDocument->IsChanged()) // 3.5
- {
- if (fDocument->fAskOnClose)
- {
- // FailInfo fi;
- // Try(fi)
- // {
- short poseResult = fDocument->PoseSaveDialog();
- switch (poseResult)
- {
- case kNoButton:
- fSavingState = kDontSave;
- break;
- case kYesButton:
- fSavingState = kDoSave;
- break;
- case cancel:
- FailOSErr(userCanceledErr);
- break;
- }
- // fi.Success();
- // }
- // else
- // {
- // this->SetValidationError(fi.error); // In case we are linked.
- // fi.ReSignal();
- // }
- }
- else
- fSavingState = kDoSave;
- }
- else
- fSavingState = kDontSave;
- }
-
- //----------------------------------------------------------------------------------------
- // TCloseDocCommand::ICloseDocCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TCloseDocCommand::ICloseDocCommand(TDocument* itsDocument,
- TAppleEvent* message,
- TAppleEvent* reply)
- {
- this->ICommand(cClose, itsDocument, kCantUndo,
- kDoesNotCauseChange, NULL);
-
- fDocument = itsDocument;
- fMessage = message;
- fReply = reply;
- fSavingState = kDoSave;
-
- // // If this command is to notify another command then do a link.
- // if (linkedCommand)
- // this->LinkToSecondary(linkedCommand);
-
- // FailInfo fi;
- // Try(fi)
- // {
- // Does the AppleEvent specifically say not to save?
- Boolean hasSaveOptions = message->HasParameter(keyAESaveOptions);
- if (hasSaveOptions)
- {
- // Get the save options
- DescType theSaveOption = message->ReadEnum(keyAESaveOptions);
- if (theSaveOption == kAEAsk)
- fSavingState = kAskSave;
- else if (theSaveOption == kAENo)
- fSavingState = kDontSave;
- }
- else if (fDocument->fAskOnClose)
- {
- short poseResult = fDocument->PoseSaveDialog();
- switch (poseResult)
- {
- case kNoButton:
- fSavingState = kDontSave;
- break;
- case kYesButton:
- fSavingState = kDoSave;
- break;
- case cancel:
- FailOSErr(userCanceledErr);
- break;
- }
- }
- // fi.Success();
- // }
- // else // Recover
- // {
- // this->SetValidationError(fi.error); // In case we are linked.
- // fi.ReSignal();
- // }
- }
-
- //----------------------------------------------------------------------------------------
- // TCloseDocCommand::DoIt:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- void TCloseDocCommand::DoIt()
- {
- if (fDocument)
- {
- if (fSavingState != kDontSave && fDocument->fCommitOnSave)
- fDocument->CommitLastCommand();
-
- // If there is actually some saving to do it should have already been done.
- fDocument->SetChangeCount(0); // Force it to not save since it will have
- // already have been saved if desired by user.
- fDocument->CloseAndFree();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TCloseDocCommand::MakeAppleEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment MACommandRes
-
- TAppleEvent* TCloseDocCommand::MakeAppleEvent()
- {
- MAVolatileInit(TAppleEvent*, mayFailEvent, NULL);
- if (fSavingState != kCancelled)
- {
- FailInfo fi;
- Try(fi)
- {
- TAppleEvent* theEvent = new TAppleEvent;
- theEvent->IAppleEvent(kAECoreSuite, kAEClose, gServerAddress, kAEWaitReply);
- mayFailEvent = theEvent;
- {
- CTempDesc theDocDesc;
- fDocument->MakeObjectSpecifier(theDocDesc, fDocument->GetSpecifierForm());
- theEvent->WriteParameter(keyDirectObject, theDocDesc);
- }
- // What kind of saving is desired.
- DescType theSaveOption = kAEAsk;
- if (fSavingState == kDoSave)
- theSaveOption = kAEYes;
- else if (fSavingState == kDontSave)
- theSaveOption = kAENo;
- theEvent->WriteEnum(keyAESaveOptions, theSaveOption);
-
- fi.Success();
- }
- else // Recover
- {
- mayFailEvent = (TAppleEvent *)FreeIfObject(mayFailEvent);
- fi.ReSignal();
- }
- }
- return mayFailEvent;
- }
-
- //========================================================================================
- // CLASS TDocument
- //========================================================================================
- #undef Inherited
- #define Inherited TCommandHandler
-
- #pragma segment MAOpen
-
- MA_DEFINE_CLASS_M2(TDocument, Inherited, MScriptableObject);
-
- //----------------------------------------------------------------------------------------
- // TDocument constructor
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- TDocument::TDocument()
- : MScriptableObject(cDocument),
- fWindowList(NULL),
- fViewList(NULL),
- fPrintInfo(NULL),
- fChangeCount(0),
- fUserSelection(NULL),
- fSavePrintInfo(TRUE),
- fSaveUserSelection(TRUE),
- #if qAttachable
- fSaveAttachedScript(TRUE),
- #endif
- fSharePrintInfo(TRUE),
- fReopenAlert(FALSE),
- fCommitOnSave(TRUE),
- fAskOnClose(TRUE),
- fIsGhostDocument(FALSE)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TDocument::IDocument:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TDocument::IDocument()
- {
- this->ICommandHandler(gDispatcher);
-
- FailInfo fi;
- Try(fi)
- {
- gDispatcher->AddDocument(this);
-
- fWindowList = NewList();
- #if qDebug
- fWindowList->SetEltType(&TWindow::fgClassDesc);
- #endif
-
- fViewList = NewList();
- #if qDebug
- fViewList->SetEltType(&TView::fgClassDesc);
- #endif
-
- fi.Success();
- }
- else // Recover
- {
- this->Free();
- fi.ReSignal();
- }
- } // TDocument::IDocument
-
- //----------------------------------------------------------------------------------------
- // TDocument::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- TDocument::~TDocument()
- {
- gDispatcher->DeleteDocument(this);
-
- fWindowList = (TList *)FreeListIfObject(fWindowList);
- fViewList = (TList *)FreeListIfObject(fViewList);
-
- // Always drop my reference
- fPrintInfo = fSharePrintInfo ? (TPrintInfo*)FreeIfObject((TObject*)(void*)fPrintInfo) : NULL; // coerce b/c this is a stub definition
-
- fUserSelection = (TDesignator *)FreeIfObject(fUserSelection);
- }
-
- //----------------------------------------------------------------------------------------
- // TDocument::AddView:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TDocument::AddView(TView* aView)
- {
- // Protect against double installation and keep in synch with window list
-
- if (fViewList && (fViewList->GetIdentityItemNo(aView) == 0))
- fViewList->Insert(aView);
- } // TDocument::AddView
-
- //----------------------------------------------------------------------------------------
- // TDocument::AddWindow:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TDocument::AddWindow(TWindow* aWindow)
- {
- // Protect against double installation and keep in synch with window list
- // doesn't already exist in list
-
- if (fWindowList && (fWindowList->GetIdentityItemNo(aWindow) == 0))
- fWindowList->Insert(aWindow);
- } // TDocument::AddWindow
-
- //----------------------------------------------------------------------------------------
- // TDocument::FindDocument:
- //----------------------------------------------------------------------------------------
- #pragma segment MARes
-
- Boolean TDocument::FindDocument(TFile*)
- {
- return FALSE;
- } // TDocument::FindDocument
-
- //----------------------------------------------------------------------------------------
- // TDocument::AttachPrintHandler:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TDocument::AttachPrintHandler(TPrintHandler* itsPrintHandler)
- {
- if (itsPrintHandler)
- itsPrintHandler->fDocument = this;
-
- TPrintMenuBehavior* aPrintMenuBehavior = new TPrintMenuBehavior;
- aPrintMenuBehavior->IPrintMenuBehavior(itsPrintHandler);
- this->AddBehavior(aPrintMenuBehavior);
- if (!fPrintInfo && fSharePrintInfo)
- fPrintInfo = itsPrintHandler->GetPrintInfo();
- } // TDocument::AttachPrintHandler
-
- //----------------------------------------------------------------------------------------
- // TDocument::DetachPrintHandler:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TDocument::DetachPrintHandler(TPrintHandler* itsPrintHandler)
- {
- TBehavior* itsManager = itsPrintHandler->GetManager();
- if (itsManager)
- {
- this->RemoveBehavior(itsManager);
- FreeIfObject(itsManager);
- }
- } // TDocument::DetachPrintHandler
-
- //----------------------------------------------------------------------------------------
- // TDocument::Changed:
- //----------------------------------------------------------------------------------------
- #pragma segment MARes
- void TDocument::Changed(ChangeID theChange,
- TObject* changedBy) // override
- {
- switch (theChange)
- {
- case cUndo:
- --fChangeCount;
- break;
- default:
- // protect from rollover (it goes negative). If your document has
- // this many changes (over 2 billion) you are truly sick!
- this->SetChangeCount(Max(this->GetChangeCount() + 1, 1));
- break;
- }
- Inherited::Changed(theChange, changedBy); // Notify dependents
- } // TDocument::Changed
-
- //----------------------------------------------------------------------------------------
- // TDocument::OpenWindowCount:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- short TDocument::OpenWindowCount()
- {
- short openDocWindows = 0;
- CWindowIterator iter(this);
-
- // See how many open windows this document has
- for (TWindow* aWindow = iter.FirstWindow(); iter.More(); aWindow = iter.NextWindow())
- if (aWindow->IsShown() && !aWindow->fFloats)
- ++openDocWindows;
- return openDocWindows;
- } // TDocument::OpenWindowCount
-
- //----------------------------------------------------------------------------------------
- // TDocument::CloseWindow:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- void TDocument::CloseWindow(TWindow* aWindow)
- {
- // The default behavior is: if the window's fClosesDocument is TRUE
- // OR if this is the document's last open window then close the
- // document, otherwise just close the window. In either case
- // the action must be recordable.
-
- if (aWindow && (aWindow->fDocument == this)) // free window
- {
- if (this->OpenWindowCount() <= 1 && !aWindow->fFloats && aWindow->IsShown())
- this->DoClose(cClose); // The window will be closed and freed
- else // as a side effect
- aWindow->DoClose(cClose);
- }
- } // TDocument::CloseWindow
-
- //----------------------------------------------------------------------------------------
- // TDocument::Close:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- void TDocument::Close()
- {
- this->Changed(mClosed,this);
-
- // Must never be called for a document related to a view in the Clipboard.
- CWindowIterator iter(this);
-
- for (TWindow* aWindow = iter.FirstWindow(); iter.More(); aWindow = iter.NextWindow())
- aWindow->CloseAndFree();
- } // TDocument::Close
-
- //----------------------------------------------------------------------------------------
- // TDocument::CloseAndFree:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- void TDocument::CloseAndFree()
- {
- this->Close();
- this->Free();
- } // TDocument::CloseAndFree
-
- //----------------------------------------------------------------------------------------
- // TDocument::MakeCloseCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- TCloseDocCommand* TDocument::MakeCloseCommand()
- {
- TCloseDocCommand* aCloseCommand = new TCloseDocCommand;
- aCloseCommand->ICloseDocCommand(cClose, this);
- return aCloseCommand;
- }
-
- //----------------------------------------------------------------------------------------
- // TDocument::DoClose:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- void TDocument::DoClose(CommandNumber aCommand,
- Boolean useAppleEvent)
- {
- Boolean oldTempAlloc = TemporaryAllocation(TRUE);
- Boolean oldObjectPerm = AllocateObjectsFromPerm(FALSE);
- TCloseDocCommand* aCloseDocCommand = new TCloseDocCommand;
- aCloseDocCommand->ICloseDocCommand(aCommand, this);
- aCloseDocCommand->fUseAppleEvent = useAppleEvent;
-
- this->PostCommand(aCloseDocCommand);
-
- TemporaryAllocation(oldTempAlloc);
- AllocateObjectsFromPerm(oldObjectPerm);
- }
-
- //----------------------------------------------------------------------------------------
- // TDocument::DeleteView:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- void TDocument::DeleteView(TView* viewToDelete)
- {
- if (fViewList)
- fViewList->Delete(viewToDelete);
-
- // Make sure the lists are in synch.
- if (fWindowList)
- fWindowList->Delete(viewToDelete);
- } // TDocument::DeleteView
-
- //----------------------------------------------------------------------------------------
- // TDocument::DeleteWindow:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- void TDocument::DeleteWindow(TWindow* windowToDelete)
- {
- if (fWindowList)
- fWindowList->Delete(windowToDelete);
-
- // Make sure the lists are in synch.
- if (fViewList)
- fViewList->Delete(windowToDelete);
- } // TDocument::DeleteWindow
-
- //----------------------------------------------------------------------------------------
- // TDocument::DoInitialState: Called for 'New' && 'Revert' [to blank] commands && for
- // default open tool icon
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TDocument::DoInitialState()
- {
- } // TDocument::DoInitialState
-
- //----------------------------------------------------------------------------------------
- // TDocument::DoMakeViews:
- //
- // E X A M P L E
- // {
- // TYOURView* aYOURView;
- // aYOURView = new TYourView;
- // aYOURView->IYOURView(this, YOURExtentRect);
- // return aYOURView;
- // }
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TDocument::DoMakeViews(Boolean forPrinting)
- {
- #if qTemplateViews
- TView * aView = NULL;
-
- if (forPrinting) // Don't need window when Finder printing.
- aView = gViewServer->DoCreateViews(this, NULL, kDefaultViewID, gZeroVPt);
- else
- aView = gViewServer->NewTemplateWindow(kDefaultWindowID, this);
-
- InstallIfPrintHandler(TPrintHandler::gPrintHandler, aView);
- #endif
- } // TDocument::DoMakeViews
-
- //----------------------------------------------------------------------------------------
- // TDocument::DoPostMakeViews:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TDocument::DoPostMakeViews(Boolean forPrinting)
- {
- if (!forPrinting)
- this->ShowWindows();
-
- TDesignator* userSelection = this->GetUserSelection();
- if (userSelection)
- this->RevealSelection(userSelection);
- } // TDocument::DoPostMakeViews
-
- //----------------------------------------------------------------------------------------
- // TDocument::DoMenuCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TDocument::DoMenuCommand(CommandNumber aCommandNumber)
- {
- //====================================================================================
- // Some commands will be posted to perform actions that must _ALWAYS_ be available.
- // The allocation cannot be allowed to fail. So we do a temp allocation which by
- // definition cannot be allowed to fail. This strategy is used wherever we want to use
- // command objects but don't want to leave the user twisting in the breeze. NOTE:
- // Don't forget to allow for this memory in your mem! resource if you copy this style
- // in your own code.
- //====================================================================================
-
- switch (aCommandNumber)
- {
- case cUndo:
- if (!gDispatcher->DoUndoRedo(this, aCommandNumber, this))
- Inherited::DoMenuCommand(aCommandNumber);
- break;
-
- case cSave:
- case cSaveAs:
- case cSaveCopy:
- this->DoSave(aCommandNumber);
- break;
-
- case cRevert:
- {
- Boolean oldTempAlloc = TemporaryAllocation(TRUE);
- Boolean oldObjectPerm = AllocateObjectsFromPerm(FALSE);
- TRevertDocCommand* aRevertDocCommand = new TRevertDocCommand;
- Boolean proceed = aRevertDocCommand->IRevertDocCommand(aCommandNumber, this);
-
- if (proceed)
- {
- aRevertDocCommand->fUseAppleEvent = TRUE; // This is the difference!
- this->PostCommand(aRevertDocCommand);
- }
- else
- aRevertDocCommand->Free();
-
- TemporaryAllocation(oldTempAlloc);
- AllocateObjectsFromPerm(oldObjectPerm);
- }
- break;
-
- default:
- Inherited::DoMenuCommand(aCommandNumber);
- break;
- }
- } // TDocument::DoMenuCommand
-
- //----------------------------------------------------------------------------------------
- // TDocument::DoSetupMenus:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- void TDocument::DoSetupMenus()
- {
- Inherited::DoSetupMenus();
-
- Enable(cSaveAs, TRUE);
- Enable(cSaveCopy, TRUE);
- if (this->IsChanged()) // 3.5
- {
- Enable(cSave, TRUE);
- Enable(cRevert, TRUE);
- }
- } // TDocument::DoSetupMenus
-
- //----------------------------------------------------------------------------------------
- // TDocument::FreeData:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- void TDocument::FreeData()
- {
- } // TDocument::FreeData
-
- //----------------------------------------------------------------------------------------
- // TDocument::FreeFromClipboard:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClipboard
-
- void TDocument::FreeFromClipboard()
- {
- this->DeleteWindow(gClipboardMgr->fClipWindow);
-
- this->Free();
- } // TDocument::FreeFromClipboard
-
- //----------------------------------------------------------------------------------------
- // TDocument::GetIsGhostDocument:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- Boolean TDocument::GetIsGhostDocument() const
- {
- return fIsGhostDocument;
- } // TDocument::GetIsGhostDocument
-
- //----------------------------------------------------------------------------------------
- // TDocument::SetIsGhostDocument:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- void TDocument::SetIsGhostDocument(const Boolean newIsGhostDocument)
- {
- fIsGhostDocument = newIsGhostDocument;
- } // TDocument::SetIsGhostDocument
-
- //----------------------------------------------------------------------------------------
- // TDocument::RegainControl:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- void TDocument::RegainControl()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TDocument::GetChangeCount:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- long TDocument::GetChangeCount()
- {
- return fChangeCount;
- } // TDocument::GetChangeCount
-
- // Added for 3.5:
- //----------------------------------------------------------------------------------------
- // TDocument::IsChanged:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- Boolean TDocument::IsChanged()
- {
- return GetChangeCount() > 0;
- } // TDocument::IsChanged
-
- //----------------------------------------------------------------------------------------
- // TDocument::DoWriteData:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- void TDocument::DoWriteData(const OSType /* aScrapType */,
- TDesignator* /* aDesignator */,
- TStream* /* aStream */)
- {
- this->SubClassResponsibility();
- } // TDocument::DoWriteData
-
- //----------------------------------------------------------------------------------------
- // TDocument::DoReadData:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- void TDocument::DoReadData(const OSType /* aScrapType */,
- TDesignator* /* aDesignator */,
- TStream* /* aStream */,
- long /* count */)
- {
- this->SubClassResponsibility();
- } // TDocument::DoReadData
-
- //----------------------------------------------------------------------------------------
- // TDocument::GetUserSelection:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- TDesignator* TDocument::GetUserSelection()
- {
- return fUserSelection;
- } // TDocument::GetUserSelection
-
- //----------------------------------------------------------------------------------------
- // TDocument::SetUserSelection:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TDocument::SetUserSelection(TDesignator* newSelection)
- {
- if (newSelection != fUserSelection)
- {
- fUserSelection = (TDesignator *)FreeIfObject(fUserSelection);
- fUserSelection = newSelection;
- }
- } // TDocument::SetUserSelection
-
- //----------------------------------------------------------------------------------------
- // TDocument::UserSelectionChanged:
- //----------------------------------------------------------------------------------------
- #pragma segment MAViewRes
-
- void TDocument::UserSelectionChanged(TView* /* changedView */)
- {
- } // TDocument::UserSelectionChanged
-
- //----------------------------------------------------------------------------------------
- // TDocument::RevealSelection:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentNonRes
-
- void TDocument::RevealSelection(TDesignator* /* designator */)
- {
- // Default behavior: select the first window of the application.
- // Call Inherited::RevealSelection() to get this default behavior if you need it.
-
- if (fWindowList)
- {
- TWindow* window = NULL;
- if ((window = (TWindow *)fWindowList->First()) != NULL)
- {
- if (!window->IsActive())
- window->Select();
- }
- }
- } // TDocument::RevealSelection
-
- //----------------------------------------------------------------------------------------
- // TDocument::RevealUndoRedo:
- //----------------------------------------------------------------------------------------
- #pragma segment MAApplicationRes
-
- void TDocument::RevealUndoRedo(TCommand* command) // override
- {
- Inherited::RevealUndoRedo(command);
-
- if (fWindowList)
- {
- TWindow* window = (TWindow *)fWindowList->First();
- if (window)
- window->Select();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TDocument::OpenAgain:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TDocument::OpenAgain(CommandNumber /*commandNumber*/,
- TDocument* /*document*/)
- {
- if (fReopenAlert)
- {
- OSErr interactErr = MAInteractWithUser();
- if (interactErr == noErr)
- {
- ParamText(fTitle, gEmptyString, gEmptyString, gEmptyString);
- StdAlert(phReopenDoc);
- }
- else if (interactErr != errAENoUserInteraction)
- FailOSErr(interactErr);
- }
-
- if (fWindowList)
- {
- TWindow* window = (TWindow *)fWindowList->First();
- if (window)
- window->Select();
- }
- } // TDocument::OpenAgain
-
- //----------------------------------------------------------------------------------------
- // TDocument::PoseSaveDialog:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- short TDocument::PoseSaveDialog()
- {
- short returnVal = kNoButton;
-
- if (this->IsChanged()) // 3.5
- {
- FailOSErr(MAInteractWithUser());
-
- CStr255 reason;
- GetIndString(reason, kIDBuzzString, gDispatcher->fDone ? bzQuitting : bzClosing);
-
- CStr255 apName;
- gDispatcher->GetApplicationName(apName); // Get the application name
- ParamText(fTitle, reason, apName, gEmptyString);
- returnVal = MacAppAlert(phSaveChanges, NULL);
- }
-
- return returnVal;
- } // TDocument::PoseSaveDialog
-
- //----------------------------------------------------------------------------------------
- // TDocument::ReadDocument:
- //----------------------------------------------------------------------------------------
- #pragma segment MAReadFile
-
- void TDocument::ReadDocument(Boolean)
- {
- this->SubClassResponsibility();
- } // TDocument::ReadDocument
-
- //----------------------------------------------------------------------------------------
- // TDocument::ReadStationery:
- //----------------------------------------------------------------------------------------
- #pragma segment MAReadFile
-
- void TDocument::ReadStationery(TFile*)
- {
- this->SubClassResponsibility();
- } // TDocument::ReadStationery
-
- //----------------------------------------------------------------------------------------
- // TDocument::RevertDocument:
- //----------------------------------------------------------------------------------------
- #pragma segment MAReadFile
-
- void TDocument::RevertDocument()
- {
- this->SubClassResponsibility();
- } // TDocument::RevertDocument
-
-
- //----------------------------------------------------------------------------------------
- // TDocument::Abandon:
- //----------------------------------------------------------------------------------------
- #pragma segment MAClose
-
- void TDocument::Abandon()
- {
- // If your document needs to do some cleanup when its being abandoned then
- // put some code in an override of this method
- } // TDocument::Abandon
-
- //----------------------------------------------------------------------------------------
- // TDocument::GetSaveLocation
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TDocument::GetSaveLocation(CommandNumber /*itsCommandNumber*/, CAEDesc& /*theSaveDesc*/)
- // Creates an CAEDesc describing where the document would be saved
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TDocument::DoSave
- //----------------------------------------------------------------------------------------
- #pragma segment MASelCommand
-
- void TDocument::DoSave(CommandNumber itsCommandNumber)
- {
- // Generate a save document command.
- Boolean oldTempAlloc = TemporaryAllocation(TRUE);
- Boolean oldObjectPerm = AllocateObjectsFromPerm(FALSE);
- TSaveDocCommand* aSaveDocCommand = new TSaveDocCommand;
-
- aSaveDocCommand->ISaveDocCommand(itsCommandNumber, this);
- aSaveDocCommand->fUseAppleEvent = TRUE; // This is the difference!
- this->PostCommand(aSaveDocCommand);
-
- TemporaryAllocation(oldTempAlloc);
- AllocateObjectsFromPerm(oldObjectPerm);
- }
-
- //----------------------------------------------------------------------------------------
- // TDocument::SaveDocument:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWriteFile
-
- void TDocument::SaveDocument(CommandNumber)
- {
- this->SubClassResponsibility();
- } // TDocument::SaveDocument
-
- //----------------------------------------------------------------------------------------
- // TDocument::SaveAgain:
- //----------------------------------------------------------------------------------------
- #pragma segment MAWriteFile
-
- void TDocument::SaveAgain(CommandNumber,
- TDocument* savingDoc)
- {
- // Don't save the file if another one of the same name is already open.
- if (savingDoc != this)
- Failure(errSaveAgain, 0);
- } // TDocument::SaveAgain
-
- //----------------------------------------------------------------------------------------
- // TDocument::GetTitle:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- void TDocument::GetTitle(CStr255& aTitle)
- {
- aTitle = fTitle;
- } // TDocument::GetTitle
-
- //----------------------------------------------------------------------------------------
- // TDocument::SetTitle:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- void TDocument::SetTitle(const CStr255& aTitle)
- {
- CWindowIterator iter(this);
-
- fTitle = aTitle;
- for (TWindow* aWindow = iter.FirstWindow(); iter.More(); aWindow = iter.NextWindow())
- aWindow->SetTitleForDoc(aTitle);
- } // TDocument::SetTitle
-
- //----------------------------------------------------------------------------------------
- // TDocument::SetChangeCount:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- void TDocument::SetChangeCount(long newChangeCount)
- {
- fChangeCount = newChangeCount;
- } // TDocument::SetChangeCount
-
- //----------------------------------------------------------------------------------------
- // TDocument::ShowReverted:
- //----------------------------------------------------------------------------------------
- #pragma segment MAReadFile
-
- void TDocument::ShowReverted()
- {
- CWindowIterator iter(this);
-
- for (TWindow* aWindow = iter.FirstWindow(); iter.More(); aWindow = iter.NextWindow())
- aWindow->ShowReverted();
- } // TDocument::ShowReverted
-
- //----------------------------------------------------------------------------------------
- // TDocument::ShowWindows:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TDocument::ShowWindows()
- {
- CWindowIterator iter(this, kIterateBackward);
-
- // Make the windows open from back to front
- for (TWindow* aWindow = iter.FirstWindow(); iter.More(); aWindow = iter.NextWindow())
- if (aWindow->fOpenInitially)
- aWindow->Open();
- } // TDocument::ShowWindows
-
- //----------------------------------------------------------------------------------------
- // TDocument::UntitledName:
- //----------------------------------------------------------------------------------------
- #pragma segment MAOpen
-
- void TDocument::UntitledName(CStr255& noName)
- {
- short preInsert;
- short constChars;
- CStr255 num;
-
- if (gNumUntitled == 1) {
- GetIndString(noName, kIDBuzzString, bzFirstUntitled);
- gNumUntitled++;
- }
- else {
- GetIndString(noName, kIDBuzzString, bzUntitled);
- NumToString(gNumUntitled, num);
- if (ParseTitleTemplate(noName, preInsert, constChars) &&
- SubstituteInTitle(noName, num, preInsert, constChars))
- gNumUntitled++;
- }
- } // TDocument::UntitledName
-
- //----------------------------------------------------------------------------------------
- // Scripting Support
- //----------------------------------------------------------------------------------------
-
- //----------------------------------------------------------------------------------------
- // TDocument::GetSpecifierForm:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScriptingRes
-
- DescType TDocument::GetSpecifierForm()
- {
- return formName;
- } // TDocument::GetSpecifierForm
-
- //----------------------------------------------------------------------------------------
- // TDocument::GetObjectProperty:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScriptingRes
-
- Boolean TDocument::GetObjectProperty(CAEDesc& thePropertyValue,
- DescType whichProperty,
- const CAEDesc& desiredType)
- {
- Boolean hasProperty = TRUE;
-
- FailInfo fi;
- Try(fi)
- {
- switch (whichProperty)
- {
- case pIsModified:
- {
- Boolean modified = IsChanged(); // 3.5
- thePropertyValue.PutBoolean(modified);
- }
- break;
-
- case pName:
- {
- CStr255 theDocName;
- GetTitle(theDocName);
- thePropertyValue.PutString(theDocName);
- }
- break;
-
- case pIndex:
- {
- // locate the nth window and return its associated document
- hasProperty = FALSE;
- MScriptableObject *myContainer = GetObjectsContainer();
- long numWindows = myContainer->CountContainedObjects(cWindow);
- for (long index = 1; index <= numWindows; index++)
- {
- TWindow *indexedWindow =
- (TWindow *)myContainer->GetIndContainedObject(cWindow, index);
- CTempDesc objectDesc;
- objectDesc.PutObject(indexedWindow->fDocument);
- if (this->CompareScriptableObjects(kAEEquals, objectDesc))
- {
- thePropertyValue.PutLong(index);
- hasProperty = TRUE;
- break;
- }
- }
- }
- break;
-
- default:
- hasProperty = MScriptableObject::GetObjectProperty(thePropertyValue, whichProperty, desiredType);
- break;
- }
- fi.Success();
- }
- else // Recover
- {
- hasProperty = FALSE;
- }
- return hasProperty;
- }
-
- //----------------------------------------------------------------------------------------
- // TDocument::GetSetPropertyInfo:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScriptingRes
-
- void TDocument::GetSetPropertyInfo(DescType whichProperty,
- CommandNumber& cmdNum,
- Boolean& canUndo,
- Boolean& causesChange,
- TCommandHandler* &theContext)
- {
- MScriptableObject::GetSetPropertyInfo(whichProperty, cmdNum, canUndo,
- causesChange, theContext);
-
- if (whichProperty == pName)
- {
- canUndo = FALSE;
- causesChange = FALSE;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TDocument::SetObjectProperty:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScriptingRes
-
- void TDocument::SetObjectProperty(const CAEDesc& thePropertyValue,
- DescType whichProperty)
- {
- switch (whichProperty)
- {
- case pName:
- {
- CStr255 theDocName;
- thePropertyValue.GetString(theDocName);
- SetTitle(theDocName);
- }
- break;
-
- case pIsModified:
- FailOSErr(errAECantSetReadOnly);
- break;
-
- default:
- MScriptableObject::SetObjectProperty(thePropertyValue, whichProperty);
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TDocument::GetContainedObject:
- //----------------------------------------------------------------------------------------
- #pragma segment OSLDispatchRes
-
- MScriptableObject* TDocument::GetContainedObject(DescType desiredType,
- DescType selectionForm,
- const CAEDesc& selectionData)
- {
- MScriptableObject * result = NULL;
- CAEDesc theSelectionData = selectionData;
- if ((desiredType == cProperty) && (theSelectionData.GetType() == pSelection))
- result = this->GetUserSelection();
- else
- result = MScriptableObject::GetContainedObject(desiredType, selectionForm, selectionData);
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // TDocument::DoAESetData:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScriptingRes
-
- void TDocument::DoAESetData(TAppleEvent*/* message */ ,
- TAppleEvent* /* reply */)
- {
- // Handles the SetData AppleEvent from the Core Suite.
- // TDocument overrides this method so it can handle this event
- // and avoid an event not handled error, but
- // it doesn't actually do anything with the data.
- }
-
- //----------------------------------------------------------------------------------------
- // TDocument::DoAEClose:
- //----------------------------------------------------------------------------------------
- #pragma segment MAScriptingRes
-
- void TDocument::DoAEClose(TAppleEvent* message,
- TAppleEvent* reply)
- {
- Boolean oldTempAlloc = TemporaryAllocation(TRUE);
- Boolean oldObjectPerm = AllocateObjectsFromPerm(FALSE);
- TCloseDocCommand* aCloseDocCommand = NULL;
- Boolean inProcess = TRUE;
-
- aCloseDocCommand = new TCloseDocCommand;
- aCloseDocCommand->ICloseDocCommand(this, message, reply);
-
- // Process the command immediately rather than posting it.
- aCloseDocCommand->Process();
-
- TemporaryAllocation(oldTempAlloc);
- AllocateObjectsFromPerm(oldObjectPerm);
- }
-
- //----------------------------------------------------------------------------------------
- // TDocument::DoAERevert
- //----------------------------------------------------------------------------------------
- #pragma segment MAOSLDispatch
-
- void TDocument::DoAERevert(TAppleEvent* message,
- TAppleEvent* reply)
- {
- MAVolatileInit(Boolean, oldTempAlloc, TemporaryAllocation(TRUE));
- MAVolatileInit(Boolean, oldObjectPerm, AllocateObjectsFromPerm(FALSE));
- MAVolatileInit(TRevertDocCommand*, aRevertDocCommand, NULL);
- Boolean inProcess = TRUE;
-
- FailInfo fi;
- Try(fi)
- {
- aRevertDocCommand = new TRevertDocCommand;
- aRevertDocCommand->IRevertDocCommand(this, message, reply, &inProcess);
-
- this->PostCommand(aRevertDocCommand);
-
- // Now we're going modal until we're sure the command
- // has completed successfully.
- while (inProcess)
- gDispatcher->PollEvent(kAllowApplicationToSleep);
-
- TemporaryAllocation(oldTempAlloc);
- AllocateObjectsFromPerm(oldObjectPerm);
-
- fi.Success();
- }
- else // Recover
- {
- FreeIfObject(aRevertDocCommand);
- TemporaryAllocation(oldTempAlloc);
- AllocateObjectsFromPerm(oldObjectPerm);
-
- fi.ReSignal();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // TDocument::DoAESave
- //----------------------------------------------------------------------------------------
- #pragma segment MAScriptingRes
-
- void TDocument::DoAESave(TAppleEvent* message,
- TAppleEvent* reply)
- {
- // Generate a save document command.
- Boolean oldTempAlloc = TemporaryAllocation(TRUE);
- Boolean oldObjectPerm = AllocateObjectsFromPerm(FALSE);
- TSaveDocCommand* aSaveDocCommand = NULL;
-
- aSaveDocCommand = new TSaveDocCommand();
- aSaveDocCommand->ISaveDocCommand(this, message, reply);
-
- // Process the command immediately rather than posting it.
- aSaveDocCommand->Process();
-
- TemporaryAllocation(oldTempAlloc);
- AllocateObjectsFromPerm(oldObjectPerm);
- }
-
-
- //----------------------------------------------------------------------------------------
- // TDocument::DoScriptCommand
- //----------------------------------------------------------------------------------------
- #pragma segment AMailerRes
-
- void TDocument::DoScriptCommand(CommandNumber aCommandNumber,
- TAppleEvent* message,
- TAppleEvent* reply)
- {
- switch (aCommandNumber)
- {
- case cAEUndo:
- case cAERedo:
- if (CommandEnabled(cUndo))
- gDispatcher->UndoRedoInContext(this, aCommandNumber);
- break;
-
- case cAERevert:
- DoAERevert(message, reply);
- break;
-
- default:
- MScriptableObject::DoScriptCommand(aCommandNumber, message, reply);
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // Container Application Support
- //----------------------------------------------------------------------------------------
-
- #if qContainer
-
- //----------------------------------------------------------------------------------------
- // TDocument::GetContainer:
- //----------------------------------------------------------------------------------------
- #pragma segment MADocumentRes
-
- CADocumentRef TDocument::GetContainer()
- {
- // Override to return the container document reference
- return NULL;
- } // TDocument::GetContainer
-
- #endif // qContainer
-
- //----------------------------------------------------------------------------------------
- // End of UDocument.cp
-
- #pragma segment Inline
-